/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * hevostietorekisteri.java
 *
 * Created on Apr 5, 2012, 12:09:12 PM
 */
package fi.ahola.tietorekisteri;

import java.awt.CardLayout;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.ImageIcon;

/**
 * Hevostietorekisteri:n pääluokka
 *
 * @author f0899
 */
public class Hevostietorekisteri extends javax.swing.JFrame {

    //Luodaan temp-hevonen
    private Hevonen h = new Hevonen();
    //Luodaan tila-muuttuja napeille
    private int tila = 0; //1-lisäähevonen,2-näytähevonen,3-haehevonen
    //Luodaan Maatila-rakenne
    private Maatila maatila = new Maatila();
    //Luodaan id jossa listasta valittu paikka
    private int id = -1;
    //Luodaan ImageIcon hevosen kuvalle
    private ImageIcon hevoIcon;
    //Luodaan Cardlayout korteille
    private CardLayout cl;
    //Alustetaan tiedostonkäsittely
    private TiedostonKasittely tk;
    //Alustetaan salaaja
    private Salaaja sal;
    //Luodaan kohde-muuttujat
    private String tiedosto = null;
    private String salasana = null;
    //Temp-arvo tallennetaanko-kysymykselle
    private int tallennaTemp;
    private int ladataankoTemp;
    //ladataan sopparin tulostin
    private VuokraSopimus vuokra = new VuokraSopimus();
    //ladataan popup-ilmoitusluokka
    private Ilmoitukset ilmo;
    //alustetaan Boolean joka kertoo salasanan toimivuudesta
    private Boolean statusBool;

    /**
     * Luokan konstruktori
     */
    public Hevostietorekisteri() {

        initComponents();
        //Otetaan CardLayout käyttöön   
        cl = (CardLayout) cardPanel.getLayout();
        //Otetaan salaaja ja tiedostonkäsittely ja popup käyttöön
        sal = new Salaaja();
        tk = new TiedostonKasittely();
        ilmo = new Ilmoitukset();
        statusBool = false;

        //Ladataan hevosen kuva resursseista ja muokataan sopivan kokoiseksi
        hevoIcon = new ImageIcon(getClass().getResource("/fi/ahola/tietorekisteri/resurssit/horse.jpg"));
        hevoIcon = new ImageIcon(hevoIcon.getImage().getScaledInstance(131, 223, BufferedImage.SCALE_SMOOTH));
        //Asetetaan labeliin
        kuvaLabel.setIcon(hevoIcon);
        try {
            String vanhaMaatila = tk.lueEdellinenMaatila();
            if (vanhaMaatila != null) {
                maatilaTextField.setText(vanhaMaatila);
            }
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
            ilmo.popupIlmoitus("sisainen");
        }

        //Näytetään salasanakysely
        naytaKortti("Salasana");

        //Päivitetään hevoslista
        paivitaLista();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sukupuoliGroup = new javax.swing.ButtonGroup();
        kayttoGroup = new javax.swing.ButtonGroup();
        vakuutusGroup = new javax.swing.ButtonGroup();
        cardPanel = new javax.swing.JPanel();
        listaPanel = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        listaScrollPane = new javax.swing.JScrollPane();
        listaList = new javax.swing.JList();
        jPanel10 = new javax.swing.JPanel();
        listaNaytaButton = new javax.swing.JButton();
        listaLisaaButton = new javax.swing.JButton();
        listaPoistaButton = new javax.swing.JButton();
        listaHaeButton = new javax.swing.JButton();
        tiedotTulostaButton = new javax.swing.JButton();
        kuvaPanel = new javax.swing.JPanel();
        kuvaLabel = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        tiedotPanel = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        puhelinTextField = new javax.swing.JTextField();
        postipaikkaTextField = new javax.swing.JTextField();
        postinroTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        omistajaTextField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        osoiteTextField = new javax.swing.JTextField();
        tiedotPeruutaButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        tiedotTallennaButton = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        nimiTextField = new javax.swing.JTextField();
        ikaTextField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        tammaRadioButton = new javax.swing.JRadioButton();
        ruunaRadioButton = new javax.swing.JRadioButton();
        varsaRadioButton = new javax.swing.JRadioButton();
        raviRadioButton = new javax.swing.JRadioButton();
        ratsuRadioButton = new javax.swing.JRadioButton();
        harrasteRadioButton = new javax.swing.JRadioButton();
        kyllaRadioButton = new javax.swing.JRadioButton();
        eiRadioButton = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        rekTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        vuokraTextField = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        erapaivaTextField = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        alkupaivaTextField = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        talliBox = new javax.swing.JCheckBox();
        kauraBox = new javax.swing.JCheckBox();
        heinaBox = new javax.swing.JCheckBox();
        kiveBox = new javax.swing.JCheckBox();
        leseBox = new javax.swing.JCheckBox();
        rehuBox = new javax.swing.JCheckBox();
        aamuBox = new javax.swing.JCheckBox();
        iltaBox = new javax.swing.JCheckBox();
        karsinaBox = new javax.swing.JCheckBox();
        pihalleBox = new javax.swing.JCheckBox();
        jLabel18 = new javax.swing.JLabel();
        loppupaivaTextField = new javax.swing.JTextField();
        muuBox = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        muumikaTextField = new javax.swing.JTextArea();
        hakuPanel = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        haeTextField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        salasanaPanel = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        maatilaTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        salasanaTextField = new javax.swing.JPasswordField();
        mainMenuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        lopetaMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Hevostietokanta");
        setMaximumSize(new java.awt.Dimension(840, 528));
        setMinimumSize(new java.awt.Dimension(840, 528));
        setPreferredSize(new java.awt.Dimension(840, 548));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        cardPanel.setPreferredSize(new java.awt.Dimension(820, 508));
        cardPanel.setLayout(new java.awt.CardLayout());

        listaScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Hevoset:"));

        listaList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaListValueChanged(evt);
            }
        });
        listaScrollPane.setViewportView(listaList);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(listaScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 830, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(listaScrollPane)
                .addContainerGap())
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Valinnat:"));
        jPanel10.setMaximumSize(new java.awt.Dimension(300, 300));
        jPanel10.setLayout(new java.awt.GridLayout(5, 1, 0, 10));

        listaNaytaButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        listaNaytaButton.setText("Näytä hevonen");
        listaNaytaButton.setMaximumSize(new java.awt.Dimension(110, 23));
        listaNaytaButton.setMinimumSize(new java.awt.Dimension(110, 23));
        listaNaytaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listaNaytaButtonActionPerformed(evt);
            }
        });
        jPanel10.add(listaNaytaButton);

        listaLisaaButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        listaLisaaButton.setText("Lisää hevonen");
        listaLisaaButton.setMaximumSize(new java.awt.Dimension(110, 23));
        listaLisaaButton.setMinimumSize(new java.awt.Dimension(110, 23));
        listaLisaaButton.setPreferredSize(new java.awt.Dimension(107, 23));
        listaLisaaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listaLisaaButtonActionPerformed(evt);
            }
        });
        jPanel10.add(listaLisaaButton);

        listaPoistaButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        listaPoistaButton.setText("Poista hevonen");
        listaPoistaButton.setMaximumSize(new java.awt.Dimension(110, 23));
        listaPoistaButton.setMinimumSize(new java.awt.Dimension(110, 23));
        listaPoistaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listaPoistaButtonActionPerformed(evt);
            }
        });
        jPanel10.add(listaPoistaButton);

        listaHaeButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        listaHaeButton.setText("Hae hevosia");
        listaHaeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listaHaeButtonActionPerformed(evt);
            }
        });
        jPanel10.add(listaHaeButton);

        tiedotTulostaButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        tiedotTulostaButton.setText("Vuokrasopimus");
        tiedotTulostaButton.setActionCommand("Näytä vuokrasopimus");
        tiedotTulostaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tiedotTulostaButtonActionPerformed(evt);
            }
        });
        jPanel10.add(tiedotTulostaButton);

        kuvaLabel.setPreferredSize(new java.awt.Dimension(131, 223));

        javax.swing.GroupLayout kuvaPanelLayout = new javax.swing.GroupLayout(kuvaPanel);
        kuvaPanel.setLayout(kuvaPanelLayout);
        kuvaPanelLayout.setHorizontalGroup(
            kuvaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(kuvaLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        kuvaPanelLayout.setVerticalGroup(
            kuvaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(kuvaLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(kuvaPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(kuvaPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        jLabel19.setText("Maatilan Hevostietokanta");
        jPanel11.add(jLabel19);

        javax.swing.GroupLayout listaPanelLayout = new javax.swing.GroupLayout(listaPanel);
        listaPanel.setLayout(listaPanelLayout);
        listaPanelLayout.setHorizontalGroup(
            listaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        listaPanelLayout.setVerticalGroup(
            listaPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(listaPanelLayout.createSequentialGroup()
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cardPanel.add(listaPanel, "listaCard");

        tiedotPanel.setPreferredSize(new java.awt.Dimension(820, 508));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Omistajan tiedot:"));

        puhelinTextField.setText("Puhelinnumero");

        postipaikkaTextField.setText("Postitoimipaikka");

        postinroTextField.setText("Postinumero");

        jLabel7.setText("Omistajan nimi:");

        omistajaTextField.setText("Nimi");

        jLabel8.setText("Osoite");

        osoiteTextField.setText("Lähiosoite");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(osoiteTextField)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(postinroTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(postipaikkaTextField))
                    .addComponent(puhelinTextField)
                    .addComponent(omistajaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(omistajaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(osoiteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(postinroTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(postipaikkaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(puhelinTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(54, Short.MAX_VALUE))
        );

        tiedotPeruutaButton1.setText("Peruuta");
        tiedotPeruutaButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tiedotPeruutaButton1ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        jLabel6.setText("Hevosen tiedot:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(388, 388, 388))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addGap(0, 14, Short.MAX_VALUE))
        );

        tiedotTallennaButton.setText("Tallenna");
        tiedotTallennaButton.setToolTipText("");
        tiedotTallennaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tiedotTallennaButtonActionPerformed(evt);
            }
        });

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Hevonen:"));

        nimiTextField.setText("Nimi");
        nimiTextField.setToolTipText("");

        ikaTextField.setText("Ikä");

        jLabel9.setText("Sukupuoli:");

        sukupuoliGroup.add(tammaRadioButton);
        tammaRadioButton.setText("Tamma");

        sukupuoliGroup.add(ruunaRadioButton);
        ruunaRadioButton.setSelected(true);
        ruunaRadioButton.setText("Ruuna / Ori");
        ruunaRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ruunaRadioButtonActionPerformed(evt);
            }
        });

        kayttoGroup.add(varsaRadioButton);
        varsaRadioButton.setText("Varsa");

        kayttoGroup.add(raviRadioButton);
        raviRadioButton.setText("Ravihevonen");

        kayttoGroup.add(ratsuRadioButton);
        ratsuRadioButton.setText("Ratsu");

        kayttoGroup.add(harrasteRadioButton);
        harrasteRadioButton.setText("Harrastehevonen");

        vakuutusGroup.add(kyllaRadioButton);
        kyllaRadioButton.setText("Kyllä");

        vakuutusGroup.add(eiRadioButton);
        eiRadioButton.setText("Ei");

        jLabel10.setText("Vakuutettu:");

        jLabel11.setText("Hevosen nimet:");

        jLabel12.setText("Ikä:");

        jLabel13.setText("Käyttötarkoitus:");

        jLabel2.setText("Rek. nro:");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel13)
                    .addComponent(jLabel10)
                    .addComponent(jLabel12))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(kyllaRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(eiRadioButton))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(varsaRadioButton)
                            .addComponent(ratsuRadioButton))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(harrasteRadioButton)
                            .addComponent(raviRadioButton)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(ikaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tammaRadioButton))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(nimiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(ruunaRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(rekTextField))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nimiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rekTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ikaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)
                            .addComponent(tammaRadioButton)
                            .addComponent(ruunaRadioButton)
                            .addComponent(jLabel12)))
                    .addComponent(jLabel11))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(varsaRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ratsuRadioButton))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jLabel13)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(kyllaRadioButton)
                            .addComponent(eiRadioButton)
                            .addComponent(jLabel10)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(raviRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(harrasteRadioButton))))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Vuokratiedot:"));

        jLabel14.setText("Vuokrahinta EUR/kk:");

        vuokraTextField.setText("Vuokra");
        vuokraTextField.setToolTipText("");

        jLabel15.setText("Vuokran eräpäivä:");

        erapaivaTextField.setText("PP");

        jLabel16.setText("Vuokran alkupvm:");

        alkupaivaTextField.setText("PP.KK.VVVV");
        alkupaivaTextField.setToolTipText("");

        jLabel17.setText("Vuokran sisältö:");

        talliBox.setText("Tallipaikka");

        kauraBox.setText("Kaura");

        heinaBox.setText("Heinä");

        kiveBox.setText("Kivennäinen");
        kiveBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kiveBoxActionPerformed(evt);
            }
        });

        leseBox.setText("Lese");
        leseBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                leseBoxActionPerformed(evt);
            }
        });

        rehuBox.setText("Ei erikoisrehuja");
        rehuBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rehuBoxActionPerformed(evt);
            }
        });

        aamuBox.setText("Aamuruokinta");

        iltaBox.setText("Iltaruokinta");

        karsinaBox.setText("Karsinan putsaus");

        pihalleBox.setText("Pihallevienti");

        jLabel18.setText("Vuokra päättyy:");

        loppupaivaTextField.setText("PP.KK.VVVV");

        muuBox.setText("Muu, mikä?");
        muuBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                muuBoxActionPerformed(evt);
            }
        });

        muumikaTextField.setColumns(20);
        muumikaTextField.setRows(5);
        muumikaTextField.setText("Muuta tietoa");
        muumikaTextField.setEnabled(false);
        jScrollPane1.setViewportView(muumikaTextField);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel18))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(vuokraTextField)
                                    .addComponent(alkupaivaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                                    .addComponent(loppupaivaTextField))
                                .addGap(18, 18, 18)
                                .addComponent(jLabel15)
                                .addGap(18, 18, 18)
                                .addComponent(erapaivaTextField))
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addGroup(jPanel7Layout.createSequentialGroup()
                                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel7Layout.createSequentialGroup()
                                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(talliBox)
                                                    .addComponent(kauraBox))
                                                .addGap(28, 28, 28)
                                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(rehuBox)
                                                    .addComponent(aamuBox)))
                                            .addGroup(jPanel7Layout.createSequentialGroup()
                                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(kiveBox)
                                                    .addComponent(leseBox))
                                                .addGap(18, 18, 18)
                                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(pihalleBox)
                                                    .addComponent(muuBox))))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(karsinaBox)
                                            .addComponent(iltaBox)
                                            .addComponent(heinaBox))))
                                .addGap(0, 202, Short.MAX_VALUE)))
                        .addGap(0, 10, 10))))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(vuokraTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(erapaivaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(alkupaivaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(loppupaivaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel17)
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(talliBox)
                    .addComponent(rehuBox)
                    .addComponent(heinaBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kauraBox)
                    .addComponent(aamuBox)
                    .addComponent(iltaBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kiveBox)
                    .addComponent(pihalleBox)
                    .addComponent(karsinaBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(leseBox)
                    .addComponent(muuBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout tiedotPanelLayout = new javax.swing.GroupLayout(tiedotPanel);
        tiedotPanel.setLayout(tiedotPanelLayout);
        tiedotPanelLayout.setHorizontalGroup(
            tiedotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tiedotPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tiedotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tiedotPanelLayout.createSequentialGroup()
                        .addGroup(tiedotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(tiedotPanelLayout.createSequentialGroup()
                        .addComponent(tiedotTallennaButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tiedotPeruutaButton1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        tiedotPanelLayout.setVerticalGroup(
            tiedotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tiedotPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tiedotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tiedotPanelLayout.createSequentialGroup()
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tiedotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tiedotTallennaButton)
                    .addComponent(tiedotPeruutaButton1))
                .addContainerGap())
        );

        cardPanel.add(tiedotPanel, "tiedotCard");

        hakuPanel.setPreferredSize(new java.awt.Dimension(820, 508));

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        jLabel20.setText("Hae Hevosia:");

        jLabel1.setText("Hevosen nimi:");

        jButton1.setText("Hae");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Peruuta");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout hakuPanelLayout = new javax.swing.GroupLayout(hakuPanel);
        hakuPanel.setLayout(hakuPanelLayout);
        hakuPanelLayout.setHorizontalGroup(
            hakuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(hakuPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(hakuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
                    .addGroup(hakuPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(hakuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, hakuPanelLayout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2))
                            .addComponent(haeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(378, 378, 378))
        );
        hakuPanelLayout.setVerticalGroup(
            hakuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(hakuPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel20)
                .addGap(18, 18, 18)
                .addGroup(hakuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(haeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(hakuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(367, Short.MAX_VALUE))
        );

        cardPanel.add(hakuPanel, "hakuCard");

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        jLabel22.setText("Maatilan Hevostietokanta");
        jPanel12.add(jLabel22);

        salasanaPanel.add(jPanel12);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tietokannan Lukitus"));
        jPanel1.setToolTipText("");

        jLabel3.setText("Maatilan nimi:");

        jLabel4.setText("Salasana:");

        jButton3.setText("Avaa lukitus");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        salasanaTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salasanaTextFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(maatilaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(salasanaTextField))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton3))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(maatilaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(salasanaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1069, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(0, 359, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 359, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 299, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(0, 95, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 95, Short.MAX_VALUE)))
        );

        salasanaPanel.add(jPanel2);

        cardPanel.add(salasanaPanel, "Salasana");

        getContentPane().add(cardPanel);

        fileMenu.setText("Tiedosto");

        jMenuItem1.setText("Tallenna tietokanta");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        jMenuItem2.setText("Lataa tietokanta");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem2);
        fileMenu.add(jSeparator1);

        jMenuItem3.setText("Vaihda tietokantaa");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem3);
        fileMenu.add(jSeparator2);

        lopetaMenuItem.setText("Lopeta");
        lopetaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lopetaMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(lopetaMenuItem);

        mainMenuBar.add(fileMenu);

        setJMenuBar(mainMenuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void lopetaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lopetaMenuItemActionPerformed
        //Poistutaan ohjelmasta
        sammuta();
    }//GEN-LAST:event_lopetaMenuItemActionPerformed

    private void listaNaytaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listaNaytaButtonActionPerformed
        //Näytetään hevosen tiedot
        naytaKortti("Nayta");
   }//GEN-LAST:event_listaNaytaButtonActionPerformed

    private void listaLisaaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listaLisaaButtonActionPerformed
        //Näytetään tyhjän hevosen tiedot
        naytaKortti("Lisaa");
   }//GEN-LAST:event_listaLisaaButtonActionPerformed

    private void listaHaeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listaHaeButtonActionPerformed
        //Näytetään haku-kortti
        naytaKortti("Haku");
   }//GEN-LAST:event_listaHaeButtonActionPerformed

    private void tiedotPeruutaButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tiedotPeruutaButton1ActionPerformed
        //Näytetään hevoslista
        naytaKortti("Lista");
   }//GEN-LAST:event_tiedotPeruutaButton1ActionPerformed

    private void tiedotTallennaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tiedotTallennaButtonActionPerformed
        //Tallennetaan hevosen tiedot ja avataan lista
        tallennaTiedot(this.h, id);
        naytaKortti("Lista");
    }//GEN-LAST:event_tiedotTallennaButtonActionPerformed

    private void ruunaRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ruunaRadioButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ruunaRadioButtonActionPerformed

    private void listaPoistaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listaPoistaButtonActionPerformed
        //Poistetaan hevonen tietorakenteesta ja päivitetään lista
        maatila.poistaHevonen(id);
        paivitaLista();
    }//GEN-LAST:event_listaPoistaButtonActionPerformed

    private void muuBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_muuBoxActionPerformed
        //Mikäli Muu-checkbox valitaan ota tekstikenttä käyttöön
        if (muuBox.isSelected() == true) {
            muumikaTextField.setEnabled(true);
        } else { //Jos ei valittu niin poista tekstikenttä käytöstä
            muumikaTextField.setEnabled(false);
        }
    }//GEN-LAST:event_muuBoxActionPerformed

    private void listaListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaListValueChanged
        //Kun valitaan hevonen listasta, asettaa id:ksi hevosen indexin
        this.id = listaList.getSelectedIndex();
    }//GEN-LAST:event_listaListValueChanged

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        //Tallennellaan tietokantaa
        tallennaTiedosto();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        //Kysytään haluaako käyttäjä varmasti ladata tietokannan
        ladataankoTemp = ilmo.popupLadataanko();
        //Mikli haluaa, puretaan ja ladataan tietokanta uudestaan
        if (ladataankoTemp == 0) {
            salausFailsafe();
        } else if (ladataankoTemp != 0) {
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        //Kun form sulkeutuu suorita sammuta
        sammuta();
    }//GEN-LAST:event_formWindowClosing

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        //Näytetään hevoslista
        naytaKortti("Lista");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //Haetaan hevosta annetun nimen perusteella
        haeHevonen(haeTextField.getText());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        //Päivitetään kohde-tiedot
        paivitaTiedot();
        //Ajetaan metodi joka suorittaa turvallisen tiedostojen avauksen
        salausFailsafe();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        //Tallennetaan muutokset
        tallennaTiedosto();
        try {
            tk.tallennaEdellinenMaatila(tiedosto);
        } catch (IOException ex) {
            ilmo.popupIlmoitus("sisainen");
        }
        tiedosto = null;
        //Näytetään lukitus-kortti
        naytaKortti("Salasana");
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void salasanaTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salasanaTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_salasanaTextFieldActionPerformed

    private void tiedotTulostaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tiedotTulostaButtonActionPerformed
        naytaKortti("Vuokrasopimus");
    }//GEN-LAST:event_tiedotTulostaButtonActionPerformed

    private void rehuBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rehuBoxActionPerformed
    }//GEN-LAST:event_rehuBoxActionPerformed

    private void kiveBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kiveBoxActionPerformed
    }//GEN-LAST:event_kiveBoxActionPerformed

    private void leseBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_leseBoxActionPerformed
    }//GEN-LAST:event_leseBoxActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Hevostietorekisteri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Hevostietorekisteri().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox aamuBox;
    private javax.swing.JTextField alkupaivaTextField;
    private javax.swing.JPanel cardPanel;
    private javax.swing.JRadioButton eiRadioButton;
    private javax.swing.JTextField erapaivaTextField;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JTextField haeTextField;
    private javax.swing.JPanel hakuPanel;
    private javax.swing.JRadioButton harrasteRadioButton;
    private javax.swing.JCheckBox heinaBox;
    private javax.swing.JTextField ikaTextField;
    private javax.swing.JCheckBox iltaBox;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JCheckBox karsinaBox;
    private javax.swing.JCheckBox kauraBox;
    private javax.swing.ButtonGroup kayttoGroup;
    private javax.swing.JCheckBox kiveBox;
    private javax.swing.JLabel kuvaLabel;
    private javax.swing.JPanel kuvaPanel;
    private javax.swing.JRadioButton kyllaRadioButton;
    private javax.swing.JCheckBox leseBox;
    private javax.swing.JButton listaHaeButton;
    private javax.swing.JButton listaLisaaButton;
    private javax.swing.JList listaList;
    private javax.swing.JButton listaNaytaButton;
    private javax.swing.JPanel listaPanel;
    private javax.swing.JButton listaPoistaButton;
    private javax.swing.JScrollPane listaScrollPane;
    private javax.swing.JMenuItem lopetaMenuItem;
    private javax.swing.JTextField loppupaivaTextField;
    private javax.swing.JTextField maatilaTextField;
    private javax.swing.JMenuBar mainMenuBar;
    private javax.swing.JCheckBox muuBox;
    private javax.swing.JTextArea muumikaTextField;
    private javax.swing.JTextField nimiTextField;
    private javax.swing.JTextField omistajaTextField;
    private javax.swing.JTextField osoiteTextField;
    private javax.swing.JCheckBox pihalleBox;
    private javax.swing.JTextField postinroTextField;
    private javax.swing.JTextField postipaikkaTextField;
    private javax.swing.JTextField puhelinTextField;
    private javax.swing.JRadioButton ratsuRadioButton;
    private javax.swing.JRadioButton raviRadioButton;
    private javax.swing.JCheckBox rehuBox;
    private javax.swing.JTextField rekTextField;
    private javax.swing.JRadioButton ruunaRadioButton;
    private javax.swing.JPanel salasanaPanel;
    private javax.swing.JPasswordField salasanaTextField;
    private javax.swing.ButtonGroup sukupuoliGroup;
    private javax.swing.JCheckBox talliBox;
    private javax.swing.JRadioButton tammaRadioButton;
    private javax.swing.JPanel tiedotPanel;
    private javax.swing.JButton tiedotPeruutaButton1;
    private javax.swing.JButton tiedotTallennaButton;
    private javax.swing.JButton tiedotTulostaButton;
    private javax.swing.ButtonGroup vakuutusGroup;
    private javax.swing.JRadioButton varsaRadioButton;
    private javax.swing.JTextField vuokraTextField;
    // End of variables declaration//GEN-END:variables

    //Tallentaa tiedot temp-hevoseen ja lisää sen maatilaan tai muokkaa vanhaa maatilassa riippuen ID:stä
    private void tallennaTiedot(Hevonen h, int id) {
        String ni = this.nimiTextField.getText();
        String ik = this.ikaTextField.getText();
        String rek = this.rekTextField.getText();

        int su = 0;
        if (this.ruunaRadioButton.isSelected() == true) {
            su = 2;
        } else if (this.tammaRadioButton.isSelected() == true) {
            su = 1;
        }

        int ka = 0;
        if (this.varsaRadioButton.isSelected() == true) {
            ka = 1;
        } else if (this.raviRadioButton.isSelected() == true) {
            ka = 2;
        } else if (this.ratsuRadioButton.isSelected() == true) {
            ka = 3;
        } else if (this.harrasteRadioButton.isSelected() == true) {
            ka = 4;
        }

        int vak = 0;
        if (this.kyllaRadioButton.isSelected() == true) {
            vak = 1;
        } else if (this.eiRadioButton.isSelected() == true) {
            vak = 2;
        }

        String om = this.omistajaTextField.getText();
        String omos = this.osoiteTextField.getText();
        String omnr = this.postinroTextField.getText();
        String ompa = this.postipaikkaTextField.getText();
        String ompu = this.puhelinTextField.getText();
        String vu = this.vuokraTextField.getText();
        String er = this.erapaivaTextField.getText();
        String al = this.alkupaivaTextField.getText();
        String lo = this.loppupaivaTextField.getText();
        String mu = "Muuta tietoa";

        //Tallennetaan valitut checkboxit taulukkoon
        int[] sis = new int[12];

        if (talliBox.isSelected() == true) {
            sis[1] = 1;
        } else {
            sis[1] = 0;
        }
        if (kauraBox.isSelected() == true) {
            sis[2] = 1;
        } else {
            sis[2] = 0;
        }
        if (kiveBox.isSelected() == true) {
            sis[3] = 1;
        } else {
            sis[3] = 0;
        }
        if (leseBox.isSelected() == true) {
            sis[4] = 1;
        } else {
            sis[4] = 0;
        }
        if (rehuBox.isSelected() == true) {
            sis[5] = 1;
        } else {
            sis[5] = 0;
        }
        if (aamuBox.isSelected() == true) {
            sis[6] = 1;
        } else {
            sis[6] = 0;
        }
        if (pihalleBox.isSelected() == true) {
            sis[7] = 1;
        } else {
            sis[7] = 0;
        }
        if (heinaBox.isSelected() == true) {
            sis[8] = 1;
        } else {
            sis[8] = 0;
        }
        if (iltaBox.isSelected() == true) {
            sis[9] = 1;
        } else {
            sis[9] = 0;
        }
        if (karsinaBox.isSelected() == true) {
            sis[10] = 1;
        } else {
            sis[10] = 0;
        }
        if (muuBox.isSelected() == true) {
            sis[11] = 1;
            mu = this.muumikaTextField.getText();
        } else {
            sis[11] = 0;
        }
        //Checkbox-sälä loppuu

        //Tallennetaan tiedot temp-hevoseen
        h.tallennaTiedot(ni, ik, su, ka, vak, om, omos, omnr, ompa, ompu, vu, er, al, lo, sis, mu, rek);

        //Suoritetaan hevosen tallennus
        if (tila == 1) {
            //lisää uuden hevosen
            maatila.lisaaHevonen(h);
        }
        if (tila == 2) {
            //muuttaa vanhaa hevosta
            maatila.muutaHevosta(h, id);
        }
    }

    //Näyttää hevosen tiedot annetun id:n perusteella
    private void naytaHevonen(int i) {

        //Jos i = -1, tee uusi hevonen temp-hevoseen
        if (i == -1) {
            h = new Hevonen();
        } else if (i != -1) { //Jos i != -1, palauta annetun indexin hevonen maatilasta
            h = this.maatila.palautaHevonen(i);
        }

        this.nimiTextField.setText(h.palautaNimi());
        this.ikaTextField.setText(h.palautaIka());


        if (h.palautaSukupuoli() == 2) {
            this.ruunaRadioButton.setSelected(true);
        } else if (h.palautaSukupuoli() == 1) {
            this.tammaRadioButton.setSelected(true);
        }

        int ka = 0;
        if (this.varsaRadioButton.isSelected() == true) {
            ka = 1;
        } else if (this.raviRadioButton.isSelected() == true) {
            ka = 2;
        } else if (this.ratsuRadioButton.isSelected() == true) {
            ka = 3;
        } else if (this.harrasteRadioButton.isSelected() == true) {
            ka = 4;
        }

        int vak = 0;
        if (this.kyllaRadioButton.isSelected() == true) {
            vak = 1;
        } else if (this.eiRadioButton.isSelected() == true) {
            vak = 2;
        }

        this.omistajaTextField.setText(h.palautaOmistaja());
        this.osoiteTextField.setText(h.palautaOsoite());
        this.postinroTextField.setText(h.palautaPostinro());
        this.postipaikkaTextField.setText(h.palautaPostipaikka());
        this.puhelinTextField.setText(h.palautaPuhelin());
        this.vuokraTextField.setText(h.palautaVuokra());
        this.erapaivaTextField.setText(h.palautaErapaiva());
        this.alkupaivaTextField.setText(h.palautaAlkupaiva());
        this.loppupaivaTextField.setText(h.palautaLoppupaiva());
        this.rekTextField.setText(h.palautaRek());

        //Asettaa checkboxit

        int[] sis = h.palautaSisalto();

        if (sis[1] == 1) {
            talliBox.setSelected(true);
        } else {
            talliBox.setSelected(false);
        }
        if (sis[2] == 1) {
            kauraBox.setSelected(true);
        } else {
            kauraBox.setSelected(false);
        }
        if (sis[3] == 1) {
            kiveBox.setSelected(true);
        } else {
            kiveBox.setSelected(false);
        }
        if (sis[4] == 1) {
            leseBox.setSelected(true);
        } else {
            leseBox.setSelected(false);
        }
        if (sis[5] == 1) {
            rehuBox.setSelected(true);
        } else {
            rehuBox.setSelected(false);
        }
        if (sis[6] == 1) {
            aamuBox.setSelected(true);
        } else {
            aamuBox.setSelected(false);
        }
        if (sis[7] == 1) {
            pihalleBox.setSelected(true);
        } else {
            pihalleBox.setSelected(false);
        }
        if (sis[8] == 1) {
            heinaBox.setSelected(true);
        } else {
            heinaBox.setSelected(false);
        }
        if (sis[9] == 1) {
            iltaBox.setSelected(true);
        } else {
            iltaBox.setSelected(false);
        }
        if (sis[10] == 1) {
            karsinaBox.setSelected(true);
        } else {
            karsinaBox.setSelected(false);
        }
        if (sis[11] == 1) {
            muuBox.setSelected(true);
            this.muumikaTextField.setText(h.palautaMuu());
            muumikaTextField.setEnabled(true);
        } else if (sis[11] != 1) {
            muuBox.setSelected(false);
            this.muumikaTextField.setText("Muuta tietoa");
            muumikaTextField.setEnabled(false);
        }
        //Checkboxien asetus loppuu

    }

    //Hevosen hakutoiminto
    private void haeHevonen(String hevo) {
        int i;
        //Etsii hevosen nimen perusteella
        i = maatila.etsiHevonen(hevo);
        //jos löytyy, asettaa sen näkyville
        if (i != -1) {
            id = i;
            h = maatila.palautaHevonen(i);
            naytaHevonen(i);
            naytaKortti("Nayta");
        } else if (i == -1) {
            ilmo.popupIlmoitus("hepohukassa");
        }
    }

    //Päivittää hevoslistan
    private void paivitaLista() {
        //lataa listan sisällön maatilan tulostanimet-metodin avulla
        listaList.setListData(maatila.tulostaNimet());
    }

    //Hoitaa CardLayoutin korttien navigoinnin
    private void naytaKortti(String kor) {
        //Näyttää hevosen tiedot-kortin hevosella
        switch (kor) {
            //Näyttää valitun hevosen tiedot tai virheen mikäli ei valittua
            case "Nayta":
                this.tila = 2;
                if (id != -1) {
                    cl.show(this.cardPanel, "tiedotCard");
                    naytaHevonen(id);
                } else if (id == -1) {
                    ilmo.popupIlmoitus("valitsehevonen");
                }
                break;

            //Näyttää hevoslistan
            case "Lista":
                paivitaLista();
                cl.show(cardPanel, "listaCard");
                break;

            //Näyttää hevoshaun
            case "Haku":
                this.tila = 3;
                cl.show(cardPanel, "hakuCard");
                break;

            //Näytää hevosen tiedot tyhjällä hevosella
            case "Lisaa":
                this.tila = 1;
                naytaHevonen(-1);
                cl.show(cardPanel, "tiedotCard");
                break;

            //Näyttää salasana-panelin
            case "Salasana":
                salasanaTextField.setText("");
                cl.show(cardPanel, "Salasana");
                break;

            //Näyttää vuokrasopimuksen valitulle hevoselle
            case "Vuokrasopimus":
                if (id != -1) {
                    h = this.maatila.palautaHevonen(id);
                    vuokra.sopimusAlustus(h);
                } else if (id == -1) {
                    ilmo.popupIlmoitus("valitsehevonen");
                }
                break;
        }
    }

    //Metodi jota käytetään aina kun halutaan tallentaa this.tiedosto
    private void tallennaTiedosto() {
        if (this.tiedosto == null || statusBool == false) {
            ilmo.popupIlmoitus("maarittamatontietokanta");
            return;
        }
        try {
            tallennaTemp = ilmo.popupTallennetaanko();
            if (tallennaTemp == 0) {
                //Tallennetaan maatilan sisältö .dat-tiedostoon
                tk.tallennaTiedosto(maatila);
                //salataan .dat-tiedosto .des-tiedostoon
                sal.salaaTiedosto();
                //jos salaaminen onnistui, poista .dat-tiedosto
                if (tk.onkoOlemassa(tiedosto + ".des")) {
                    tk.poistaTiedosto(tiedosto + ".dat");
                } else if (tallennaTemp != 0) {
                }
            }
        } catch (Exception ex) {
            ilmo.popupIlmoitus("tiedostotallennus");
        }
    }

    //Sammutusmetodi joka tallentaa tietokannan
    private void sammuta() {
        if (tiedosto != null) {
            try {
                tallennaTiedosto();
                tk.tallennaEdellinenMaatila(tiedosto);
            } catch (IOException ex) {
                ilmo.popupIlmoitus("tiedostotallennus");
            }
        }
        System.exit(0);
    }

    //Metodi päivittää kohdetiedoston ja sen salasanan muuttujat salasana-panelista
    private void paivitaTiedot() {

        //Ladataan annetut tiedot muuttujaan
        this.tiedosto = this.maatilaTextField.getText();
        this.salasana = String.valueOf(this.salasanaTextField.getPassword());

        //Asetetaan kohdetiedot koneistoihin
        tk.asetaKohde(tiedosto);
        sal.asetaKohde(tiedosto, salasana);
    }

    //Metodi tarkistaa mitä tiedostoja löytyy, yrittää purkaa salauksen
    //jos epäonnistuu niin ilmoittaa
    //jos onnistuu niin avaa tiedoston ja vaihtaa korttia
    private void salausFailsafe() {

        int tie = tk.tarkistaTiedostot(".dat", ".des");

        if (this.tiedosto == null) {
            ilmo.popupIlmoitus("maarittamatontietokanta");
            return;
        }

        if (tie == 1) {
            try {
                //vain dat
                this.maatila = tk.avaaTiedosto();
            } catch (Exception ex) {
                ilmo.popupIlmoitus("tiedostoavaus");
                return;
            }
            naytaKortti("Lista");

        } else if (tie == 2) {
            try {
                statusBool = sal.puraTiedosto();
            } catch (Exception ex) {
                ilmo.popupIlmoitus("tiedostopurku");
                return;
            }

            //des tai datdes
            if (statusBool) {
                try {
                    maatila = tk.avaaTiedosto();
                    naytaKortti("Lista");
                } catch (Exception ex) {
                    ilmo.popupIlmoitus("tiedostoavaus");
                }
            } else if (!statusBool) {
                //Mikäli väärä salasana, ilmoittaa virheestä
                ilmo.popupIlmoitus("vaarasalasana");
            }
        } else if (tie == 3) {
            //ei kumpaakaan
            //luodaan uusi maatila
            maatila = new Maatila();
            try {
                tk.tallennaTiedosto(maatila);
                statusBool = true;
                naytaKortti("Lista");
            } catch (Exception ex) {
                ilmo.popupIlmoitus("tiedostotallennus");
            }
        } else if (tie == -1) {
            ilmo.popupIlmoitus("sisainen");
        }
    }
}
